package cn.seocoo.platform.api.controller.user;

import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.user.domain.AppUser;
import cn.seocoo.platform.user.dto.UserFrom;
import cn.seocoo.platform.user.dto.UserTypeDto;
import cn.seocoo.platform.user.service.IAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: ApiUserCheckController
 * @description: 用户校验controller
 * @author: wujian
 * @Date: 2019-12-30 14:48
 **/
@RequestMapping("api/check")
@RestController
public class ApiUserCheckController {

    @Autowired
    private IAppUserService iAppUserService;

    /**
     * @Author WuJian
     * @Description //校验用户类型
     * @Date 15:58 2019/12/30
     * @Param [appUserId]
     * @return cn.seocoo.platform.api.util.JSONResult
     **/
    @GetMapping("/checkUserType")
    public JSONResult checkUserType(Integer appUserId) {
        AppUser appUser = iAppUserService.selectAppUserById(appUserId);
        UserTypeDto dto = new UserTypeDto();
        if(appUser != null ){
            dto.setUserType(appUser.getUserType());
            dto.setUserStatus(appUser.getUserAuthStatus());
            dto.setUnitStatus(appUser.getUnitAuthStatus());
            return JSONResult.ok(dto);
        }else{
            return  JSONResult.errorMsg(JSONResult.ERROR_MSG);
        }
    }

    /**
     * @Author WuJian
     * @Description //卖车时,校验用户发布的车辆
     * @Date 15:58 2019/12/30
     * @Param [appUserId]
     * @return cn.seocoo.platform.api.util.JSONResult
     **/
    @GetMapping("/checkUserCarNum")
    public JSONResult checkUserCarNum(Integer appUserId) {
        try {
            Map<String,String> map = iAppUserService.checkUserCarNum(appUserId);
            return JSONResult.ok(map);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.errorMsg(JSONResult.ERROR_MSG);
        }

    }
}
